<!-- 功能：创建SANLUN | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月16日 22:30:38 -->
<template>
  <!-- 弹出框 -->
  <a-modal v-model:open="visible" title="选择逻辑卷类型" width="500px" class="y-modal" okText="创建" @ok="onSubmit" @cancel="onCancel">
    <a-form :label-col="{ span: 6 }" :wrapper-col="{span: 14}">
      <a-form-item label="逻辑卷类型" v-bind="validateInfos.type">
        <a-radio-group v-model:value="modelRef.type">
          <a-radio :style="radioStyle" value="puTongLuoJiJuan">普通逻辑卷</a-radio>
          <a-radio :style="radioStyle" value="ziJingJianLuoJiJuan">自精简逻辑卷</a-radio>
        </a-radio-group>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup>
const radioStyle = reactive({
  display: 'flex',
  height: '30px',
  lineHeight: '30px'
})

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
})

const { visible } = toRefs(props)

// 定义组件的事件
const emits = defineEmits(['update:visible'])

import { Form } from 'ant-design-vue'

const useForm = Form.useForm

const modelRef = reactive({
  type: 'puTongLuoJiJuan'
})

const rulesRef = reactive({
  type: [
    {
      required: true,
      message: '请选择逻辑卷类型'
    }
  ]
})

const { resetFields, validate, validateInfos, mergeValidateInfo } = useForm(modelRef, rulesRef)
const onSubmit = () => {
  validate()
    .then(() => {
      console.log('创建SANLUN>>', toRaw(modelRef))
      onCancel()
    })
    .catch(err => {
      console.log('error', err)
    })
}

const onCancel = () => {
  // 触发自定义事件来通知父组件关闭弹窗
  emits('update:visible', false)
}
</script>

<style scoped>
.ant-row {
  margin-bottom: 10px;
}
</style>